package com.huike.web.controller.system;

import com.huike.clues.domain.dto.RoleStatusDto;
import com.huike.clues.service.ISysRoleService;
import com.huike.common.config.BaseContext;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.domain.entity.SysRole;
import com.huike.common.core.domain.model.LoginUser;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.ServletUtils;
import com.huike.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/system/role")
public class SysRoleController extends BaseController {
    @Autowired
    private ISysRoleService sysRoleService;
    @GetMapping("list")
    public TableDataInfo<SysRole> list(SysRole role) {
        startPage();
        List<SysRole> sysRoles = sysRoleService.selectRoleList(role);
        return getDataTable(sysRoles);
    }

    @PostMapping
    public AjaxResult add(@RequestBody SysRole sysRole) {
        sysRole.setCreateBy(BaseContext.getCurrentUser().getCreateBy());
        sysRole.setUpdateBy(BaseContext.getCurrentUser().getUpdateBy());
        sysRole.setUpdateTime(new Date());
        sysRole.setCreateTime(new Date());
        sysRoleService.add(sysRole);
        return AjaxResult.success();
    }
    @PutMapping("changeStatus")
    public AjaxResult changeStatus(@RequestBody RoleStatusDto roleStatusDto){
     sysRoleService.changeStatus(roleStatusDto);
        return AjaxResult.success();
    }
    @GetMapping("{roleId}")
    public AjaxResult info(@PathVariable("roleId") Long roleId){
        SysRole sysRole=sysRoleService.findById(roleId);
        return AjaxResult.success(sysRole);
    }
    @DeleteMapping("{role}")
    public AjaxResult deleteById(@PathVariable("role") List<Long> roleId){
        sysRoleService.deleteById(roleId);
        return AjaxResult.success();
    }
    @PutMapping
    public AjaxResult updateRole(@RequestBody SysRole sysRole){
        sysRoleService.updateRole(sysRole);
        return AjaxResult.success();
    }
    @PutMapping("dataScope")
    public AjaxResult updateDataScope(@RequestBody SysRole sysRole){
        sysRoleService.updateRole(sysRole);
        return AjaxResult.success();
    }


}
